<?php

/*
 * 淘宝客获取数据类
 * @author kane.xie mr.ziyong@qq.com    
 * @time 2012.5.19
 */

class Taobao {
    var $c;
    /*
     * 实例化TOP框架
     */

    public function initTop() {
        define('TOP_SDK_WORK_DIR', TOP_TMP_PATH);//设置缓存路径
        require_once EXTEND_PATH . '/TopSdk.php';
        $this->c = new TopClient;
        $this->c->appkey = KC('top_app_key');
        $this->c->secretKey = KC('top_secret_key');
        $this->c->gatewayUrl = "http://gw.api.taobao.com/router/rest";
    }

    /*
     * 转换商品链接
     */

    public function getItem($itemid,$nick=false) {
        $nick=!$nick?KC('top_taobao_nick'):$nick;
        $this->initTop();
        $req = new TaobaokeItemsConvertRequest;
        $req->setFields("num_iid,title,click_url,iid,commission,commission_rate,commission_num,commission_volume,volume,pic_url,price");
        $req->setNick($nick);
        $req->setOuterCode("kk");
        $req->setNumIids("$itemid");
//        $req->setPid(KC('top_taobao_pid'));
        $req->setIsMobile("false");
        $resp = $this->c->execute($req);
        unset($this->c);
        $res=(array)$resp->taobaoke_items->taobaoke_item;
        if(!empty($res)){
            return $res;
        }else{
            return false;
        }
    }

}

?>